package com.aat.dxfy.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@MultipartConfig(location="/opt/logs", maxFileSize = 1024*1024*200)
@WebServlet("/upload/action.do")
public class Upload extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		Part part = null;
		try {
			part = request.getPart("f1");// 获取part用于处理上传的文件
		} catch (IllegalStateException e) {
			e.printStackTrace();
		}

		if (part == null)
			return;

		System.out.println("t1:" + request.getParameter("t1"));
		String sss=part.getHeader("content-disposition");
		String ss=sss.split(";")[2].trim();
		String s=ss.split("=")[1];
		String saveName = s.substring(1, s.length()-1);
		part.write(saveName);

		response.setContentType("text/html;charset=UTF-8");
		response.sendRedirect("/index.jsp");
	}

}
